import 'package:sainbainu/common/utils/util.dart';

/// 小组列表
class GroupListResponse {
  List<CroupItemResponse> rows;
  int total;

  GroupListResponse({
    required this.rows,
    required this.total,
  });

  factory GroupListResponse.fromJson(Map<String, dynamic> json) =>
      GroupListResponse(
        total: json['total'] as int,
        rows: (json['rows'] as List)
            .map((e) => CroupItemResponse.fromJson(e))
            .toList(),
      );
}

class CroupItemResponse {
  int? groupId;
  String? groupName;
  String? cover;
  int? memberNum;
  int? noteNum;
  String? uniqueTag;
  int? joinFlag; // 是否已加入小组；0.否；1.是

  CroupItemResponse({
    this.groupId,
    this.groupName,
    this.cover,
    this.memberNum,
    this.noteNum,
    this.uniqueTag,
    this.joinFlag,
  });

  factory CroupItemResponse.fromJson(Map<String, dynamic> json) {
    return CroupItemResponse(
      groupId: json['groupId'] as int?,
      groupName: json['groupName'] as String?,
      cover: json['cover'] as String?,
      memberNum: json['memberNum'] as int?,
      noteNum: json['noteNum'] as int?,
      uniqueTag: Util.generateRandomString(),
      joinFlag: json['joinFlag'] as int?,
    );
  }

  Map<String, dynamic> toJson() => {
        'groupId': groupId,
        'groupName': groupName,
        'cover': cover,
        'memberNum': memberNum,
        'noteNum': noteNum,
        'joinFlag': joinFlag,
      };
}
